<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 课程管理
                </el-breadcrumb-item>
                <el-breadcrumb-item>新增课程</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="form-box">
                <el-form ref="form" :model="form2" label-width="80px">
                    <el-form-item label="课程名">
                        <el-input v-model="param.coursename" style="width:40% "></el-input>
                    </el-form-item>
                    <el-form-item label="人数限额">
                        <el-input v-model="param.coursemax" style="width:40% "></el-input>
                    </el-form-item>
                    <el-form-item label="课程性质">
                        <el-select v-model="param.isPrivate" placeholder="请选择是否私有" style="width: 40%">
                            <el-option key="是" label="是" value="是"></el-option>
                            <el-option key="否" label="否" value="否"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="课程定价">
                        <el-input v-model="param.price" style="width:40% " :readonly="param.isPrivate=='是'?false:true"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">确定</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    import {addCourse} from "../../api/admin";

    export default {
        name: 'baseform',
        data() {
            return {
                form2: {
                    name: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: true,
                    type: ['步步高'],
                    resource: '小天才',
                    desc: '',
                    options: []
                },
                param: {
                    coursename: '',
                    coursemax:'',
                    isPrivate: '',
                    price:'0.00'

                }
            };
        },
        methods: {
            onSubmit() {
                addCourse(this.param).then(res => {
                    console.log(this.param);
                    if (res.state==2000) {
                        this.$message.success('添加成功！');
                        this.param.coursename='';
                        this.param.coursemax='';
                        this.param.nature='';
                        this.param.price='';
                        location.reload();
                    }else{
                        this.$message.error(res.message);
                    }

                })
            }
        }
    };
</script>
